package com.company.management.service.reward.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.company.management.domain.reward.TalentUser;
import com.company.management.domain.reward.dto.TalentUserQueryDTO;
import com.company.management.domain.reward.vo.TalentUserVO;
import com.company.management.mapper.reward.TalentUserMapper;
import com.company.management.service.reward.TalentUserService;
import io.jsonwebtoken.lang.Collections;
import org.apache.commons.lang3.StringUtils;
import org.modelmapper.ModelMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @description:
 * @author: wangbin
 * @time: 2025/3/3
 **/

@Service
public class TalentUserServiceImpl extends ServiceImpl<TalentUserMapper, TalentUser> implements TalentUserService {
    @Resource
    private ModelMapper modelMapper;
    /**
     * @param talentUserQueryDTO
     * @return
     */
    @Override
    public List<TalentUserVO> findByPage(TalentUserQueryDTO talentUserQueryDTO) {
        List<TalentUser> list = lambdaQuery().like(StringUtils.isNotEmpty(talentUserQueryDTO.getUserName()), TalentUser::getUserName, talentUserQueryDTO.getUserName())
                .eq(TalentUser::getEmpStatus,0)
                .list();
        return list.stream().map(u-> modelMapper.map(u, TalentUserVO.class)).collect(Collectors.toList());
    }

    @Override
    public TalentUser findIsAdminByUserId(Integer userId) {
        return this.getById(userId);
    }

    @Override
    public List<TalentUserVO> findByCreateUseId(Collection<Integer> userIds) {
        List<TalentUser> list = lambdaQuery().in(!Collections.isEmpty(userIds), TalentUser::getUserId, userIds).list();
        return list.stream().map(u-> modelMapper.map(u, TalentUserVO.class)).collect(Collectors.toList());
    }
}
